package org.yunmai.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.yunmai.entity.SysDept;
import org.yunmai.vo.SysDeptVO;

import java.util.List;

/**
* @author Administrator
* @description 针对表【sys_dept】的数据库操作Mapper
* @createDate 2025-06-03 19:47:42
* @Entity org.yunmai.entity.SysDept
*/
@Mapper
public interface SysDeptMapper extends BaseMapper<SysDept> {

    @Select({
            "<script>",
            "SELECT ",
            "   d.id, ",
            "   d.name, ",
            "   d.master, ",
            "   d.parent_id, ",
            "   parent.name AS parent_name, ",
            "   parent.master AS parent_master ",
            "FROM sys_dept d ",
            "LEFT JOIN sys_dept parent ON d.parent_id = parent.id ",
            "WHERE 1=1 ",
            "<if test='keyword != null and keyword != \"\"'>",
            "   AND (d.name LIKE CONCAT('%', #{keyword}, '%') ",
            "   OR d.master LIKE CONCAT('%', #{keyword}, '%') ",
            "   OR parent.name LIKE CONCAT('%', #{keyword}, '%')) ",
            "</if>",
            "ORDER BY d.parent_id, d.id ",
            "LIMIT #{offset}, #{pageSize}",
            "</script>"
    })
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "master", column = "master"),
            @Result(property = "parentId", column = "parent_id"),
            @Result(property = "parentName", column = "parent_name"),
            @Result(property = "parentMaster", column = "parent_master")
    })
    List<SysDeptVO> selectDeptPage(@Param("offset") int offset, @Param("pageSize") int pageSize, @Param("keyword") String keyword);

}




